
#ifndef	__FECAB_STORE_SERVICE_HPP_2010__
#define	__FECAB_STORE_SERVICE_HPP_2010__

#include <string>

#include <boost/thread/mutex.hpp>

#include <lua.hpp>

#include "fecab/packet.pb.h"
#include "fecab/store.hpp"
#include "service.hpp"

namespace	fecab	{
namespace	server	{

class	StoreService
		:	public Service
{
public	:
	StoreService( const std::string config_file );
	virtual	~StoreService();


public	:
	virtual	int	handle( const std::string& request, std::string& response );

private	:
	void	initializeLua( void );

	int		handlePUT( fecab::Packet& pkt_request, fecab::Packet& pkt_response );
	int		handleGET( fecab::Packet& pkt_request, fecab::Packet& pkt_response );
	int		handleDELETE( fecab::Packet& pkt_request, fecab::Packet& pkt_response );

	int		handleSPUT( fecab::Packet& pkt_request, fecab::Packet& pkt_response );
	int		handleSMPUT( fecab::Packet& pkt_request, fecab::Packet& pkt_response );

	int		callLUA( const std::string& table, 
					 const std::string& key, 
					 const std::string& old_value, 
					 const std::string& data, 
					 const std::string& script, 
					 const std::string& crumb, 
					       std::string& new_value );

private	:
	std::string	_config_filename;

	fecab::StoreManager		_store_manager;
	fecab::Store*	_store_p;

	lua_State*	_L;
	boost::mutex	_mutex_lua;
};

}	// namespace server
}	// namespace fecab

#endif	//	__FECAB_STORE_SERVICE_HPP_2010__

